package com.woniuxy.intellihome.mapper;

import com.woniuxy.intellihome.entity.Order;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2021-08-11
 */
public interface OrderMapper extends BaseMapper<Order> {
    //根据user_id 查询 用户明细
    @Select("select * from m_order where user_id=#{user_id}")
    List<Order> getByUserId(int userId);

    //增加order，并获取新增order——id信息
    @Insert("insert into m_order(order_num,user_id,order_time,accept,tel,address,prices,sendmode,paymode,pay_time,send_time,accept_time,status)" +
            " values(#{orderNum},#{userId},#{orderTime},#{accept},#{tel},#{address},#{prices},#{sendmode},#{paymode},#{payTime},#{sendTime},#{acceptTime},#{status})")
    @Options(useGeneratedKeys = true,keyProperty = "id", keyColumn = "id")
    void add(Order order);

    //根据订单编号查询订单
    @Select("select * from m_order where order_num = #{orderNum}")
    Order getByOrderNum(String orderNum);
}
